package com.miraclemiles.controller;

import java.security.Principal;
import java.util.Arrays;
import java.util.List;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 需要认证的请求
 */
@RestController
@RequestMapping("/users")
public class UserController {

	@GetMapping("/list")
	public List<String> list() {
//		 SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		return Arrays.asList("test1", "test2", "test3");
	}
	
	@RequestMapping("/user")
	public Principal user(Principal principal) {
		//principal在经过security拦截后，是org.springframework.security.authentication.UsernamePasswordAuthenticationToken
		//在经OAuth2拦截后，是OAuth2Authentication
	    return principal;
	}

}
